package com.yoomiito.app.present.cicle;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseLazyFragmentPresenter;
import com.yoomiito.app.model.cicle.CircleReommendGoodsData;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.fragment.cicle.CircleGoodRecommendFragment;
import com.yoomiito.app.utils.NetworkUtils;
import com.yoomiito.app.utils.SpannableUtils;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class CicleGoodRecommendFmPresenter_1 extends BaseLazyFragmentPresenter<CircleGoodRecommendFragment> {

    public CicleGoodRecommendFmPresenter_1(AppConfig appConfig) {
        super(appConfig);
    }

    public void getGoodRecommentData(long page){
        if (NetworkUtils.checkNetPermission(getV().getContext())){
            getV().finishRefresh();
            return;
        }
        YmApi.getYmService()
                .getRecommendGoods(page)
//                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<CircleReommendGoodsData>() {
                    @Override
                    public void onSuccess(CircleReommendGoodsData data) {
                        getV().setGoodRecommendData(data);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        if (!SpannableUtils.isEmptyOr0(error.getMsg())){
//                            YMToast.showText();
                        }
                    }
                });
    }
}
